<?php
/**
 * 后台日志管理
 *
 * @Author: yuanji <fenglangyj@139.com>
 * @DateTime: 12-11-3 下午1:44
 * @Copyright (c) 2012 http://www.magentoui.com All rights reserved.
 * @Version  $Id: sss.php,v 1.0 uw Exp $
 * @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 */
class AdminLogAction extends CommonAction {
    /**
     * 重写搜索条件
     * @return HashMap
     */
    protected function _search(){
		$user_id= trim($_REQUEST['user_id']);
		if(!empty($user_id)){
			$map["user_id"] = $user_id;
		}
		$action= trim($_REQUEST['action']);
		if(!empty($action)){
			$map["action"] = $action;
		}
		$function= trim($_REQUEST['function']);
		if(!empty($function)){
			$map["function"] = $function;
		}
		$word = trim($_REQUEST['word']);
		if(!empty($word)){
			if(is_numeric($word)){
				$map['id'] = $word;
			}else{
				$map['log_info'] = array('like',"%$word%");
			}
		}
		$create_time = trim($_REQUEST['create_time']);
		if(!empty($create_time)){
			$create_time = strtotime($create_time);
			$map['create_time'] = array(array('gt',$create_time),array('lt',$create_time+3600*24));
		}
		//print_r($map);
		return $map;

	}
	public function _before_index(){
		$node = D('node');
		$list = $node->field("name,title,level")->where('status = 1')->select();
		$node_list = array();
		foreach($list as $vo){
			$node_list[$vo['level']][$vo['name']] = $vo['title'];
		}
		$this->assign('node_list',$node_list);
		
		$user = D('user');
		$list = $user->field("id,nickname,account")->select();
		$user_list = array();
		foreach($list as $vo){
			$user_list[$vo[id]] = $vo;
		}
		$this->assign('user_list',$user_list);
	}

    /**
     * 清空日志
     */
    public function truncate(){
		$m = M();
		$m->query('TRUNCATE '.C('DB_PREFIX').'admin_log');
		$this->success('ok');
	} 
}